package com.szbber.medical.board.ui.fragment

import android.graphics.Color
import android.graphics.drawable.Drawable
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.orhanobut.logger.Logger
import com.szbber.commen.base.BaseFragment
import com.szbber.commen.base.BaseRoutePath
import com.szbber.commen.bean.ScheduleBean
import com.szbber.medical.board.R
import com.szbber.medical.board.databinding.BoardItemCarelabelBinding
import com.szbber.medical.board.databinding.BoardItemOperationBinding
import kotlinx.android.synthetic.main.board_fragment_setting.*
import kotlinx.android.synthetic.main.board_fragment_today_operation.*

class TodayOperationFragment : BaseFragment() {

    private  var data:List<ScheduleBean.OperationVo> ? = null
    private var arr = mutableListOf<String>("#b3e5fc", "#b39ddb","#ce93d8",
        "#f48fb1","#80cbc4", "#ffcc80" ,"#c5e1a5","#80cbc4")
    private var iconarr = mutableListOf<Int>(
        R.drawable.icon_operation1,R.drawable.icon_operation2,R.drawable.icon_operation3,
        R.drawable.icon_operation4,R.drawable.icon_operation5,R.drawable.icon_operation6,
    )
    companion object {
        fun getInstance(data:List<ScheduleBean.OperationVo> ): TodayOperationFragment {
            val sf = TodayOperationFragment()
            sf.data = data
            return sf
        }
    }

    override fun getLayoutResId(): Int = R.layout.board_fragment_today_operation

    override fun initView(bundle: Bundle?) {
        data?.apply {    setData(this) }

    }

    fun setData(data: List<ScheduleBean.OperationVo>) {
        val adapter = object :BaseQuickAdapter<ScheduleBean.OperationVo, BaseViewHolder>(
            R.layout.board_item_operation, data.toMutableList()
        ){
            override fun convert(holder: BaseViewHolder, item: ScheduleBean.OperationVo) {
                val binding =
                    DataBindingUtil.bind<ViewDataBinding>(holder.itemView) as BoardItemOperationBinding
               binding.operationMV = item
              binding.llItem.setBackgroundColor(Color.parseColor(arr[(0 until arr.size).random()]))
                binding.ivIcon.setBackgroundResource(iconarr[(0 until iconarr.size).random()])
            }
        }

        mRecyclerView.adapter = adapter
        mRecyclerView.layoutManager = LinearLayoutManager(activity)
    }
}